/*
 * @lc app=leetcode.cn id=872 lang=javascript
 *
 * [872] 叶子相似的树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root1
 * @param {TreeNode} root2
 * @return {boolean}
 */
var leafSimilar = function(root1, root2) {
    let res1=[]
    let res2=[]
    let dfs=function(node,res){
        if(!node)return
        dfs(node.left,res)
        if(!node.left&&!node.right){
            res.push(node.val)
        }
        dfs(node.right,res)
    }
    dfs(root1,res1)
    dfs(root2,res2)
    return res1.toString()==res2.toString()
};
// @lc code=end

